import {connect} from 'dva';
import React, {PureComponent} from 'react';
import {Form, Input,InputNumber, Upload, message, Switch, Icon, Select, Radio, Modal} from 'antd';
import styles from './UsercreateModal.less';

const FormItem = Form.Item;
const {Option} = Select;


@connect(state => ({
    profile: state.profile,
}))
@Form.create()
export default class UserPointChangeModal extends PureComponent {
    state = {
           point:100,
           type: '+'
    }

    handleCancel = () => {
        this.props.dispatch({
            type: 'profile/changeModal',
            payload: {pointAddShow:false}
        });
    }
    handleSubmit = (e) => {
        // this.props.dispatch({
        //     type: 'user/status',
        //     payload: {
        //         status,
        //         items: this.state.selectedRows,
        //     },
        //     callback: () => {
        //         this.setState({
        //             selectedRows: [],
        //         });
        //     },
        // });


        this.props.form.validateFields((err, values) => {
            if (!err) {

                values.user_id = this.props.user ? this.props.user.id : 0;
                this.props.dispatch({
                    type: 'profile/changePoint',
                    payload: values,
                    callback: (result) => {
                        
                            this.props.form.resetFields();
                            this.handleCancel();
                            this.props.onPointChange()
                        
                    },
                });
            }
        });
    }
    
    render() {
        const {getFieldDecorator} = this.props.form;
        const item = this.state.item;
        const {profile: { confirmLoading, pointAddShow}} = this.props;

        const formItemLayout = {
            labelCol: {
                span: 6,
            },
            wrapperCol: {
                span: 14,
            },
        };
        return (
          <Modal
            onOk={this.handleSubmit}
            confirmLoading={confirmLoading}
            onCancel={this.handleCancel}
            title="积分管理"
            visible={pointAddShow}
          >
            <Form onSubmit={this.handleSubmit}>
              <FormItem className={styles.formItem} {...formItemLayout} label="积分">
                {getFieldDecorator('point', {
                            initialValue: this.state.point,
                        })(<InputNumber min={0}  />)}
              </FormItem>
              <FormItem className={styles.formItem} {...formItemLayout} label="类型">
                {getFieldDecorator('type', {
                            initialValue: this.state.type,
                            rules: [
                                {
                                    required: true,
                                    message: '请选择类型',
                                },
                            ],
                        })(
                          <Radio.Group>
                            <Radio value="+">增加</Radio>
                            <Radio value="-">减少</Radio>
                          </Radio.Group>
                        )}
              </FormItem>
              <FormItem className={styles.formItem} {...formItemLayout} label="积分备注">
                {getFieldDecorator('remark', {
                            rules: [
                                {
                                    required: true,
                                    message: '请输入备注',
                                },
                            ],
                        })(
                         <Input.TextArea />
                        )}
              </FormItem>
              
            </Form>
          </Modal>
        );
    }
}



